package com.sztest.jayjun.view;

import android.content.Context;
import android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.StateListDrawable;
import android.util.AttributeSet;
import android.widget.ImageView;

import com.sztest.jayjun.R;
import com.sztest.jayjun.utils.LogUtils;

import androidx.annotation.Nullable;

/*
 *  @项目名：  jayjun
 *  @包名：    com.sztest.jayjun.view
 *  @文件名:   FyztImageView
 *  @创建者:   okmin
 *  @创建时间:  2022/7/14 18:21
 *  @描述：    TODO
 */
public class FyztImageView extends ImageView {
    private AnimationDrawable mAnimationDrawable;
    public FyztImageView(Context context) {
        super(context);
    }

    public FyztImageView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public FyztImageView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public FyztImageView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }

    /**
     * true 播动画,false 不播动画
     * @param selected
     */
    @Override
    public void setSelected(boolean selected){
        super.setSelected(selected);
        if (selected) {
            setBackgroundResource(R.drawable.bg_fyzt_end_anim);
            mAnimationDrawable = (AnimationDrawable) getBackground();
            LogUtils.e("mAnimationDrawable="+(mAnimationDrawable==null));
            if (mAnimationDrawable!=null) {
                mAnimationDrawable.start();
            }
        }else {
            if (mAnimationDrawable!=null) {
                mAnimationDrawable.stop();
            }
            setBackgroundResource(R.drawable.selector_main_fyzt);
        }
    }
}
